package com.pine.common.threadpool.core;

import com.pine.common.threadpool.ThreadPoolConfig;
import com.pine.common.threadpool.ThreadPoolConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * 线程池配置工厂
 *
 * @author pine manage
 * @since 2024-08-28
 */
public class ThreadPoolConfigFactory {

    private static final Map<String, ThreadPoolConfig> THREAD_POOL_CONFIG_MAP = new HashMap<>(16);

    /**
     * 添加线程池配置
     *
     * @param businessCode     业务编码
     * @param businessKey      业务key
     * @param threadPoolConfig 线程池配置
     */
    public static void addThreadPoolConfig(String businessCode, String businessKey, ThreadPoolConfig threadPoolConfig) {
        THREAD_POOL_CONFIG_MAP.put(ThreadPoolConstant.THREAD_POOL_NAME_FORMAT.formatted(businessCode, businessKey), threadPoolConfig);
    }

    /**
     * 获取线程池配置
     *
     * @param businessCode 业务编码
     * @param businessKey  业务key
     * @return 线程池配置
     */
    public static ThreadPoolConfig getThreadPoolConfig(String businessCode, String businessKey) {
        return THREAD_POOL_CONFIG_MAP.get(ThreadPoolConstant.THREAD_POOL_NAME_FORMAT.formatted(businessCode, businessKey));
    }

    public static Map<String, ThreadPoolConfig> getThreadPoolConfigMap() {
        return THREAD_POOL_CONFIG_MAP;
    }
}
